import Vue from 'vue'
import Cookies from 'js-cookie'
import 'normalize.css/normalize.css'
import Element from 'element-ui'
//引入拖拽js
import './assets/directives'
//
import mavonEditor from 'mavon-editor'
import 'mavon-editor/dist/css/index.css'
// 数据字典
import dict from './components/Dict'
// 权限指令
import permission from './components/Permission'
import './assets/styles/element-variables.scss'
// global css
import './assets/styles/index.scss'
import App from './App'
import store from './store'
import router from './router/routers'
import './assets/icons' // icon
import './router/index' // permission control
import VueForm from '@/components/VueForm/index'
import VueClipboard from 'vue-clipboard2'
import components from "@/components/index";
import VueEditor from 'vue2-editor'
import publicUpload from './utils/publicUpload';
import '../src/assets/iconfont/iconfont'
import '../src/assets/iconfont/iconfont.css'
import x2js from 'x2js'
import publicJs from './assets/public'
import request from './utils/request';
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import Treeselect from '@riophae/vue-treeselect'
import * as filters from './utils/filter' // global filters

import '../src/assets/styles/projectGol/gol.scss'
Vue.prototype.$x2js = new x2js()
Vue.use(VueEditor)
Vue.use(VueForm)
Vue.use(VueClipboard)
Vue.use(mavonEditor)
Vue.use(permission)
Vue.use(dict)
Vue.use(components)
Vue.use(Element, {
  size: Cookies.get('size') || 'small' // set element-ui default size
})
Vue.prototype.$publicUpload = publicUpload
Vue.prototype.$httpGet = request.get
Vue.prototype.$httpPost = request.post
// 公用方法
Vue.prototype.$publicJs = publicJs
Vue.component('Treeselect', Treeselect)
Vue.prototype.$headerSearch = true
Vue.config.productionTip = false
Vue.prototype.$bus = new Vue() // event Bus 用于无关系组件间的通信。
Vue.prototype.$headerSearch = true
let instance = null
//注册过滤器
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

let mainHistory = null

function render(props = {}) {
  // hash模式不需要base
  // const { container, routerBase } = props
  // const router = new VueRouter({
  //   base: window.__POWERED_BY_QIANKUN__ ? routerBase : process.env.BASE_URL,
  //   // mode: 'history', // hash模式所有都要加前缀
  //   routes,
  // })
  const { container } = props
  // 用于拦截跳转到主工程登录页
  if (mainHistory) {
    // 以乾坤微前端启动有此值
    router.$mainHistory = mainHistory
  }

  instance = new Vue({
    router,
    store,
    render: (h) => h(App)
  }).$mount(container ? container.querySelector('#app') : '#app')
}

if (!window.__POWERED_BY_QIANKUN__) {
  // 这里是子应用独立运行的环境，实现子应用的登录逻辑
  render()
}

export async function bootstrap() {
  console.log('[vue] vue app bootstraped')
}

export async function mount(props) {
  console.log('[vue] props from main framework', props)
  // Vue.use(props.data.commonUI)
  mainHistory = props.mainHistory
  Vue.prototype.$mainHistory = mainHistory
  render(props)
}
import {
  Table,
  Column,
  Checkbox,
  Select,
  Pager,
  Icon,
  Input,
} from 'vxe-table'
Vue.use(Table).use(Column).use(Checkbox).use(Icon).use(Pager).use(Select).use(Input)
export async function unmount() {
  instance.$destroy()
  instance.$el.innerHTML = ''
  instance = null
}
